from django.db.models import CharField,ForeignKey,DateTimeField,IntegerField,BooleanField,DateField,DecimalField,TextField,DO_NOTHING,PROTECT
from apps.vadmin.op_drf.models import CoreModel

# 资产构件
class Components(CoreModel):
    serial = CharField(max_length=128,null=True,verbose_name="序列号")
    name = CharField(max_length=256,null=False,verbose_name="资产构件名称")
    category = ForeignKey(to="assets.Categories",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="分类id")
    deleted_datetime = DateTimeField(null=True,verbose_name="删除时间")
    qty = IntegerField(null=False,default=0,verbose_name="数量")
    location = ForeignKey(to="assets.Locations",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="关联位置")
    checkout_qty = IntegerField(null=False,default=0,verbose_name="借出数量")
    purchase_date = DateField(null=True,verbose_name="采购日期")
    purchase_cost = DecimalField(max_digits=20,decimal_places=2,null=True,verbose_name="采购价格")
    order_number = CharField(max_length=128,null=True,verbose_name="订单编号")
    min_amt = IntegerField(null=False,default=1,verbose_name="最小数量")
    supplier = ForeignKey(to="assets.Suppliers",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="供应商id")
    manufacturer = ForeignKey(to="assets.Manufacturers",null=True,db_constraint=False,on_delete=PROTECT,verbose_name="制造商id")
    image = CharField(max_length=256,null=True,verbose_name="图片url")
    notes = TextField(null=True,verbose_name="备注")

    class Meta:
        verbose_name = '资产构件'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.name}"


